package com.peza.bikelog.common.domain.polar;

import com.peza.bikelog.common.util.Util;


public class SMode {

	private static Util util = Util.getInstance();
	
	private boolean speed; // (0=off, 1=on)
	private boolean cadence; // (0=off, 1=on)
	private boolean altitude; // (0=off, 1=on)
	private boolean power; // (0=off, 1=on)
	private boolean powerLeftRightBalance; // (0=off, 1=on)
	private boolean powerPedallingIndex; // (0=off, 1=on)
	private boolean hrCCdata; // 0 = HR data only, 1 = HR + cycling data
	private boolean usUnits; // US / Euro unit 0 = Euro 
	private boolean airPressure; // (0=off, 1=on)

	public SMode(String data) {
		
		speed 					= util.convertToBoolean(""+data.charAt(0));
		cadence 				= util.convertToBoolean(""+data.charAt(1));
		altitude 				= util.convertToBoolean(""+data.charAt(2));
		power 					= util.convertToBoolean(""+data.charAt(3));
		powerLeftRightBalance 	= util.convertToBoolean(""+data.charAt(4));
		powerPedallingIndex 	= util.convertToBoolean(""+data.charAt(5));
		hrCCdata 				= util.convertToBoolean(""+data.charAt(6));
		usUnits 				= util.convertToBoolean(""+data.charAt(7));
		airPressure 			= util.convertToBoolean(""+data.charAt(8));

	}

	public boolean isSpeed() {
		return speed;
	}

	public void setSpeed(boolean speed) {
		this.speed = speed;
	}

	public boolean isCadence() {
		return cadence;
	}

	public void setCadence(boolean cadence) {
		this.cadence = cadence;
	}

	public boolean isAltitude() {
		return altitude;
	}

	public void setAltitude(boolean altitude) {
		this.altitude = altitude;
	}

	public boolean isPower() {
		return power;
	}

	public void setPower(boolean power) {
		this.power = power;
	}

	public boolean isPowerLeftRightBalance() {
		return powerLeftRightBalance;
	}

	public void setPowerLeftRightBalance(boolean powerLeftRightBalance) {
		this.powerLeftRightBalance = powerLeftRightBalance;
	}

	public boolean isPowerPedallingIndex() {
		return powerPedallingIndex;
	}

	public void setPowerPedallingIndex(boolean powerPedallingIndex) {
		this.powerPedallingIndex = powerPedallingIndex;
	}

	public boolean isHrCCdata() {
		return hrCCdata;
	}

	public void setHrCCdata(boolean hrCCdata) {
		this.hrCCdata = hrCCdata;
	}

	public boolean isUsUnits() {
		return usUnits;
	}

	public void setUsUnits(boolean usUnits) {
		this.usUnits = usUnits;
	}

	public boolean isAirPressure() {
		return airPressure;
	}

	public void setAirPressure(boolean airPressure) {
		this.airPressure = airPressure;
	}
	
	@Override
	public String toString(){
		
		StringBuffer buffer = new StringBuffer();
		String value = speed ? "1" : "0";
		buffer.append(value); 
		value = cadence ? "1" : "0";
		buffer.append(value);
		value = altitude ? "1" : "0";
		buffer.append(value);
		value = power ? "1" : "0";
		buffer.append(value);
		value = powerLeftRightBalance ? "1" : "0";
		buffer.append(value);
		value = powerPedallingIndex ? "1" : "0";
		buffer.append(value); 
		value = hrCCdata ? "1" : "0";
		buffer.append(value); 
		value = usUnits ? "1" : "0";
		buffer.append(value); 
		value = airPressure ? "1" : "0";
		buffer.append(value);
		
		
		return buffer.toString();
		
	}

}
